package  
{
	import org.flixel.*;
	
	public class Player extends FlxSprite{
		[Embed(source="/../media/BalanceKeeper.png")] private var ImgPlayer:Class;


		public function Player (X:Number, Y:Number) {
			super(X, Y);
			loadGraphic(ImgPlayer, false);
			maxVelocity.x = 120;			//walking speed
			acceleration.y = 400;			//gravity
			elasticity = 0.1;

			//drag.x = 200;
			
			

		}
		
		override public function update():void {
			
			
			

			//Smooth slidey walking controls)
			
			
			if (!isTouching(FLOOR))
			{
				acceleration.x = 0;

			}
			
			else
			{
				
				if (FlxG.keys.A || FlxG.keys.LEFT){
					velocity.x -= 7;
					if (velocity.x > 0) 
						acceleration.x = 0;

				
				}
				else if (FlxG.keys.D || FlxG.keys.RIGHT){
					velocity.x += 7;
					if (velocity.x < 0) 
						acceleration.x = 0;

				}
				
				else if(!(FlxG.keys.A || FlxG.keys.D) || !(FlxG.keys.LEFT || FlxG.keys.RIGHT)){
					acceleration.x = -8 * velocity.x;
				}
				//Jump controls
				if(FlxG.keys.W || FlxG.keys.SPACE || FlxG.keys.UP)
				{
					velocity.y += -acceleration.y*0.51;
					//play("jump");
				}
				//Animations
				
				//else if(velocity.x > 0)
				//	play("walk");
				//else if(velocity.x < 0)
				//	play("walk_back");
				//else
				//	play("idle");
			}

			

			if(FlxG.keys.A || FlxG.keys.LEFT)
				velocity.x -= 4;
			if(FlxG.keys.D || FlxG.keys.RIGHT)
				velocity.x += 4;
			//else if(velocity.y < 0)
			//	play("jump");
			//else
			//	play("flail");

		}
		
		
		
	}

}